package base;

import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.*;

public class EssaiFtp {
	public static void main(String[] args) {

		boolean error = false;
		try {
			int reply;
			FTPClient ftp = new FTPClient();
			String ipCobalt = "137.129.98.8";
			ftp.connect(ipCobalt);
			ftp.login("anonymous", "anonymous");
			System.out.println("Connected to " + ipCobalt + ".");
			System.out.print(ftp.getReplyString());

			// After connection attempt, you should check the reply code to
			// verify
			// success.
			reply = ftp.getReplyCode();

			if (!FTPReply.isPositiveCompletion(reply)) {
				ftp.disconnect();
				System.err.println("FTP server refused connection.");
				System.exit(1);
			}
			// transfer files
			ftp.logout();
			if (ftp.isConnected()) {
				try {
					ftp.disconnect();
				} catch (IOException ioe) {
					// do nothing
				}
			}
		} catch (IOException e) {
			error = true;
			e.printStackTrace();
		} finally {
		}
		System.exit(error ? 1 : 0);
	}

	// FTPClient f = new FTPClient();
	// String ipCobalt = "137.129.98.8" ;
	// try {
	// f.connect(ipCobalt);
	// } catch (SocketException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// } catch (IOException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// try {
	// f.login("anonymous", "anonymous");
	// } catch (IOException e) {
	// // TODO Auto-generated catch block
	// e.printStackTrace();
	// }
	// FTPFile[] files = listFiles(".");

}
